/**
 * 
 */
package de.pernpas.calendar.servlet.event;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.pernpas.calendar.service.EventService;

/**
 * @author stefanpernpaintner
 *
 */
public class DeleteEvent extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException{
		String key = req.getParameter("key");
		if(key.equals("all")){
			// delete all Event Elements
			EventService.deleteAll();
			res.sendRedirect("/calendar.jsp");
		} else {
			EventService.delete(Long.parseLong(key));
			res.sendRedirect("/detail.jsp?year=" + req.getParameter("year") + 
					"&month=" + req.getParameter("month") + 
					"&day=" + req.getParameter("day"));
		}
		
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException{
		doGet(req, res);
	}
}
